/* 文章分页管理
 * @Author: Leil 
 * @Date: 2018-09-05 22:17:17 
 * @Last Modified by: Leil
 * @Last Modified time: 2018-09-05 23:59:38
 */
const postModel = require('../models/post')
const config = require('config-lite')(__dirname)

async function getPageNum() {
    let count = 0
    await postModel.getPostsCount()
            .then(res => {
                count = res
            })
            .catch(error => {
                console.log(error)
            })
    let pageNum = Math.ceil(count / config.blogNumPrePage)
    console.log(pageNum)
    return pageNum
}

async function getPostsByPage(currentPage) {
    console.log(currentPage)
    let data
    await postModel.getPostsByPage(currentPage)
            .then(posts => {
                // console.log(posts)
                data = posts
            })
            .catch(error => {
                console.log(error)
            })
    return data
}


module.exports = {
    getPageNum,
    getPostsByPage
}